<template>
	<view class="newCar-page" :style="'background-color:' + pageBackgroundColor + ';'">
		<cu-custom bgColor="bg-blue" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">
				<text class="nav-title" @tap="event_clickNewCarTitle"
					:class="currentTitle === '新车'?'nav-title-selected':''">新车</text>
				<text class="nav-title" @tap="event_clickSeachCarTitle"
					:class="currentTitle === '寻车'?'nav-title-selected':''">寻车</text>
			</block>
		</cu-custom>
		<addressSearchFixed ref="setAddres" @searchBtn='event_clickSearchBtn' :isShowAddress="false">
		</addressSearchFixed>
		<view class="newCar-page__content" :style="[{marginTop: SeachBar + 'px'}]">
			<!-- 车系列表 -->
			<view>
				<!-- 新能源车、平行进口车 -->
				<view class="carSeries-list">
					<view :class="i === 0 ? 'carSeries-list__left' : 'carSeries-list__right'"
						v-for="(carType, i) in carTypeRow1List" :key="i">
						<view class="carSeries-card"
							@click="$disableDoubleClick(event_clickCarType, 'canClick', carType.code)">
							<view class="carSeries-card__text">
								<text class="title">{{carType.title}}</text>
								<text class="desc">全部车型</text>
							</view>
							<view style="flex: 1;"></view>
							<image class="carSeries-card__image" :src="carType.imagePath"></image>
						</view>
					</view>
				</view>
				<!-- 商务改装车、特惠折扣车 -->
				<view class="carSeries-list margin-top-sm">
					<view  :class="i === 0 ? 'carSeries-list__left' : 'carSeries-list__right'"
						v-for="(carType, i) in carTypeRow2List" :key="i">
						<view class="carSeries-card"
							@click="$disableDoubleClick(event_clickCarType, 'canClick', carType.code)">
							<view class="carSeries-card__text">
								<text class="title">{{carType.title}}</text>
								<text class="desc">全部车型</text>
							</view>
							<view style="flex: 1;"></view>
							<image class="carSeries-card__image" :src="carType.imagePath"></image>
						</view>
					</view>
				</view>
			</view>
			<!-- 常用品牌 -->
			<view class="carCommonBrand-list margin-top-sm">
				<view class="carCommonBrand-list__title-background">
					<view class="carCommonBrand-list__title">常用品牌</view>
				</view>
				<view class="carCommonBrand-list__content">
					<view class="carBrand" v-for="(carType, i) in commonBrands" :key="i"
						@click="$disableDoubleClick(event_clickCarType, 'canClick', carType.id)">
						<image class="carBrand__image" :src="carType.cover_url" mode="scaleToFill"></image>
						<view class="carBrand__name">
							{{carType.name}}
						</view>
					</view>
				</view>
			</view>
			<view class="" style="margin-top: 310px;margin-bottom: 90px;">
				<uni-indexed-list :options="carBrandInfoList" @click="toSelectIndex" />
			</view>

			<view style="width: 100%;height: 5px;">
			</view>
		</view>
		<view class="bottom-content">

			<view class="" @click="btnHandler(1)">
				<image class="bottom-content-img" src="@/static/home-select.png" mode="scaleToFill"></image>
				<view class="">
					首页
				</view>
			</view>
			<view class="" @click="btnHandler(2)">
				<image class="bottom-content-img" src="@/static/send_car_source_select.png" mode="scaleToFill"></image>
				<view class="">
					发布车源
				</view>
			</view>
			<view class="" @click="btnHandler(3)">
				<image class="bottom-content-img"  src="../../../static/me_select.png" mode=""></image>
				<view class="">
					我的
				</view>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	import {
		getNewCarBrandList,
		getCommonBrandsList
	} from '@/api/brand.js';
	import cuCustom from "@/components/custom-nav/cu-custom.vue";
	import addressSearchFixed from "@/components/addressSearch/addressSearchFixed.vue";
	export default {
		components: {
			cuCustom,
			addressSearchFixed
		},
		data() {
			return {
				commonBrands: [],
				index: 0,
				temp: 0,
				CustomBar: this.CustomBar,
				SeachBar: this.SeachBar,
				currentTitle: '新车',
				carTypeRow1List: [{
						title: '新能源车',
						code: 'xny',
						imagePath: '../../../static/newCar/1.png'
					},
					{
						title: '平行进口车',
						code: 'pxjk',
						imagePath: '../../../static/newCar/2.png'
					}
				],
				carTypeRow2List: [{
						title: '商务改装车',
						code: 'swgz',
						imagePath: '../../../static/newCar/3.png'
					},
					{
						title: '特惠折扣车',
						code: 'thzk',
						imagePath: '../../../static/newCar/4.png'
					}
				],

				canClick: true, // 可以点击（用于防止页面重复点击）
				customNavTitleIndex: 1, // 页面标题下标
				pageBackgroundColor: '#FFFFFF', // 页面背景颜色
				sreachContent: '', //寻车列表中搜索框的功能
				carBrandInfoList: [], // 车品牌数据列表
			}
		},
		onShow() {
			
			//常用品牌
			const value = uni.getStorageSync('login')
			if (value) {
				this.users_id = value.id
			}
			// this.users_id
			getCommonBrandsList("9FE0AAB0-EF09-ED77-E05A-F02E5DA7A71C", 41).then(res => {
				this.commonBrands = res.data
				console.log("commonBrands===", this.commonBrands);
			})
			this.init();

			try {
				this.$utils.stopPage(); //禁止页面本身的滑动
				this.$refs.setAddres.setAddres()
			} catch (e) {
				//TODO handle the exception
			}

		},
		onHide() {
			// this.$utils.movePage()
		},
		onUnload() {
			// this.$utils.movePage()
		},
		methods: {
			init: function() {
				this.$utils.log("init");
				this.api_getNewCarBrandList()
			},
			// 点击——新车
			event_clickNewCarTitle: function() {
				this.$utils.log("新车")
				this.currentTitle = '新车'
			},
			// 点击——寻车
			event_clickSeachCarTitle: function() {
				this.$utils.log("寻车")
				this.currentTitle = '寻车'
				uni.navigateTo({
					url: '/pages/home/newCarSearch/newCarSearch'
				})
			},
			// 点击——页面顶部标题
			event_clickTitle: function(titleIndex) {
				this.$utils.log("在index页面点了了title" + titleIndex)
				if (this.customNavTitleIndex != titleIndex) {
					this.$utils.log("不等   " + titleIndex);
					this.sreachContent = '';
					this.$refs.setAddres.inputValueUpdata()
				}
				this.customNavTitleIndex = titleIndex;

				if (this.customNavTitleIndex == 1) {
					this.pageBackgroundColor = "#FFFFFF"
				} else {
					this.pageBackgroundColor = "#F5F5F5"
				}
			},
			// 点击——搜索框搜索按钮
			event_clickSearchBtn: function(content) {
				this.sreachContent = content
				this.$utils.log("点击搜索" + content)
				if (this.customNavTitleIndex == 2) {
					const loaction = uni.getStorageSync('address')
				} else {
					const loaction = uni.getStorageSync('address')
				}
			},
			// 点击——各个车型
			event_clickCarType: function(CarTypeCode) {
				
				this.$utils.log("点击车型" + CarTypeCode)
				switch (CarTypeCode){
					case 'xny':
					uni.navigateTo({
						url: '/newEnergy/newEnergyVehicle/newEnergyVehicle' 
					})
				     // this.$utils.log("新能源车")
					break;
					case 'pxjk':
					uni.navigateTo({
						url: '/newEnergy/parallelImportCar/parallelImportCar' 
					})
					 this.$utils.log("平行进口车")
					break;
					case 'swgz':
					 this.$utils.log("商务改装车")
					 uni.navigateTo({
						 url:"/pages/business/business"
					 })
					break;
					case 'thzk':
						uni.navigateTo({
							url:"/pages/discountCar/discountCar"
						})
					 this.$utils.log("特惠折扣车")
					break;
					default:
						break;
				}
			},
			// 点击——用户常用车型
			event_clickUserFrequentlyUsedCarType: function(CarTypeCode) {
				this.$utils.log("点击车型" + CarTypeCode)
			},

			api_getNewCarBrandList: function() {
				getNewCarBrandList().then(res => {
					res.data.forEach(item => {
						item.letter = item.key;
						item.value.forEach(i => {
							i.pic = i.cover_url
						})
						item.data = item.value
					})
					this.carBrandInfoList = res.data

					console.log("this.carBrandInfoList==", this.carBrandInfoList);
					this.$forceUpdate()
				})
			},
			disableDoubleClick: function(fn, handklerName, id) {
				console.log(123);
				console.log("disableDoubleClick", handklerName, id);
				if(id=="thzk"){
					uni.navigateTo({
						url:"/pages/discountCar/discountCar"
					})
				}
			},
			toSelectIndex: function(key, i) {
				console.log("列表 key===", key, "i===", i);
			},
			btnHandler: function(num) {
				switch (num) {
					case 1:
						uni.reLaunch({
							url:"/pages/home/index/index"
						})
						break;
					case 2:
						console.log('发布车源')
						break;
					case 3:
						console.log('我的')
						uni.reLaunch({
							url:"/pages/user/me/me"
						})
						break;
				}
			}
		}
	}
</script>

<style>
	.newCar-page {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: auto;
	}

	.newCar-page .newCar-page__content {
		height: 100vh;
		/* 父元素设置相对定位 */
		position: relative;
		background-color: #F7F8FA;
		padding: 26rpx 28rpx 0 28rpx;
	}

	/* 车系列表 */
	.carSeries-list {
		display: flex;
	}

	.carSeries-list__left {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.carSeries-list__right {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;

		margin-left: 14rpx;
	}

	/* 车系卡片 */
	.carSeries-card {
		border-radius: 10px;
		background-color: #FFFFFF;
		width: 100%;
		flex: 1;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.carSeries-card__text {
		display: flex;
		flex-direction: column;
		margin-left: 30rpx;
	}

	.carSeries-card__text .title {
		/* font-family: Source Han Sans CN; */
		font-weight: bold;
		font-size: 14px;
		text-align: left;
	}

	.carSeries-card__text .desc {
		margin-top: 5px;
		text-align: left;
		/* font: Alimama ShuHeiTi; */
		font-size: 12px;
		color: #666666;
	}

	.carSeries-card__image {
		width: 58rpx;
		height: 50rpx;
		margin: 39rpx 50rpx 39rpx auto;
	}

	/* 常用车品牌列表 */
	.carCommonBrand-list {
		text-align: left;
		background-color: #FFFFFF;
		/* margin: 0px 14px 0px 14px; */
		border-radius: 10px;
		padding: 28rpx;
	}

	.carCommonBrand-list__title-background {
		width: 75px;
		background: url(@/static/bac-small.png);
		background-size: 100% 100%;
	}

	.carCommonBrand-list__title {
		width: 140rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #000026;
		opacity: 1;
		margin-left: 2rpx;
	}

	.carCommonBrand-list__content {
		display: flex;
		/* justify-content: center; */
		padding: 37rpx 0 9rpx 0;
	}

	/* 车品牌 */
	.carBrand {
		/* flex: 1; */
		width: 140rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.carBrand__image {
		height: 56rpx;
		width: 56rpx;
	}

	.carBrand__name {
		margin-top: 28rpx;

		font-size: 28rpx;
		font-weight: bold;
	}

	/* 车品牌索引列表 */
	.newCar-indexed-list__title-wrapper {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 6px 0px 4px 14px;
	}

	.newCar-indexed-list__title {
		font-size: 28rpx;
		font-family: DIN Alternate;
		font-weight: bold;
		color: #1C2125;
		opacity: 1;
	}

	.newCar-indexed-list__menu {
		display: flex;
		position: fixed;

		top: 50%;
		right: 0;
		-webkit-transform: translate(-50%, -50%);
		transform: translate(0, -50%);

		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.nav-title {
		font-size: 36rpx;
		/* font-family: Source Han Sans CN; */
		font-weight: 500;
		line-height: 0rpx;
		color: #FFFFFF;
		opacity: 1;
		margin-left: 20rpx;
		margin-right: 20rpx;
	}

	.nav-title-selected {
		/* font-family: Alimama ShuHeiTi; */
		font-weight: bold;
	}

	.content-row {
		display: flex;
		flex-direction: row;
		align-items: center;
	}


	.pad18-14 {
		padding: 18rpx 28rpx;
	}

	.pad6-14-4 {
		padding: 6px 0px 4px 14px;
	}

	.iamge-class {
		width: 100rpx;
		height: 52rpx;
	}

	.marginLeft5 {
		margin-left: 5px;
	}

	.brand-name-class {
		font-size: 28rpx;
		/* font-family: Source Han Sans CN; */
		font-weight: 400;
		color: #000026;
		opacity: 1;
	}

	.right-view-text {
		font-size: 20rpx;
		font-family: DIN Alternate;
		font-weight: bold;
		color: #999999;
		padding: 4rpx;
	}

	.right-view-text-select {
		font-size: 20rpx;
		/* font-family: DIN Alternate; */
		font-weight: bold;
		color: #0E59EA;
		padding: 4rpx;
	}

	.bottom-content {
		position: fixed;
		bottom: 0;
		height: 62px;
		width: 100%;
		background-color: #FFFFFF;
		box-shadow: 0rpx -2rpx 4rpx 0rpx rgba(204, 204, 204, 0.4);
		display: flex;
		justify-content: space-around;
		align-items: center;
		text-align: center;
	}

	.bottom-content-img {
		width: 25px;
		height: 25px;
	}
</style>